<template>
  <div class="addstudent">
    <el-row :gutter="30">
      <el-col :span="12">
        <el-row>

        </el-row>
        <el-row class="mt-10">
          <el-form ref="form" :model="form" label-width="100px" :rules="rules" autocomplete="off">

            <el-form-item label="管理员账号" prop="username">
              <el-input v-model="form.username" placeholder="管理员账号" autocomplete="off"></el-input>
            </el-form-item>

            <el-form-item label="管理员密码" prop="password">
              <el-input v-model="form.password" placeholder="管理员密码" type="password" autocomplete="new-password"></el-input>
            </el-form-item>


            <el-form-item>
              <el-button type="primary" @click="submitForm('form')">立即创建</el-button>
              <el-button>取消</el-button>
            </el-form-item>
          </el-form>
        </el-row>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  export default {
    name: "addadmin",
    data() {
      return {
        fileList: [],
        form: {
          username: '',
          password: '',
        },
        rules: {
          username: [
            {required: true, message: '请输入学生名字', trigger: 'blur'},

          ],
          password: [
            {required: true, message: '请输入学生学号', trigger: 'blur'}
          ]


        }
      }
    },
    methods: {

      submitForm(formName) {
        var self = this;
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$http.post(this.URL.api + `user/addadmin`, self.form)
              .then(res => {
                if (res.data.flag) {
                  this.$message({
                    message: '添加成功',
                    type: 'success'
                  });
                  this.form = {
                    username: '',
                    password: '',
                  }

                } else {
                  this.$message.error(res.data);
                }


              })

          } else {

            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },

      onSubmit() {
        console.log('submit!');
      },
      handleRemove(file, fileList) {
        console.log(file, fileList);
      },
      handlePreview(file) {
        console.log(file);
      },
      handleExceed(files, fileList) {
        this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
      },
      beforeRemove(file, fileList) {
        return this.$confirm(`确定移除 ${file.name}？`);
      }
    },
    mounted: function () {

    }

  }
</script>

<style scoped>

</style>
